package golf;

import java.sql.ResultSet;
import java.sql.SQLException;

import database.DAO;

public class Room {
	public static int ROOM_IS_FULL = 1;
	public static int PASSWORD_NOT_CORRECT = 2;
	
	public static String ROOMTYPE_GAME = "게임";
	public static String ROOMTYPE_SQUARE = "광장";
	int no;
	int seqNo;
	int chnNo;
	String name;
	int now_person_no;
	int limit_person_no;
	String password;
	int limit_level;
	String roomType;
	char finished;
	
	
	Game game;
	Square square;


	public Room(){
		
	}
	
	public Room(ResultSet rs){
		try {
			setNo( rs.getInt("ROOMNO") );
			setName(rs.getString("ROOMNM"));
			setNow_person_no(rs.getInt("NOWCHARNO"));
			setLimit_person_no(rs.getInt("LIMITPERNO"));
			setPassword(rs.getString("PWD"));
			setLimit_level(rs.getInt("LIMITLEV"));
			setRoomType(rs.getString("ROOMTYPENAME"));
			setFinished(rs.getString("FINISHED").charAt(0));
			if( getRoomType().compareTo(ROOMTYPE_GAME) == 0 ){
				setGame(DAO.getInstance().getGame(getNo()));
			}else{
				setSquare(DAO.getInstance().getSquare(getNo()));
			}
			System.out.println("Room()완료");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public int getNo() {
		return no;
	}
	public void setNo(int no) {
		this.no = no;
	}
	public int getSeqNo() {
		return seqNo;
	}
	public void setSeqNo(int seqNo) {
		this.seqNo = seqNo;
	}
	public int getChnNo() {
		return chnNo;
	}
	public void setChnNo(int chnNo) {
		this.chnNo = chnNo;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getNow_person_no() {
		return now_person_no;
	}
	public void setNow_person_no(int now_person_no) {
		this.now_person_no = now_person_no;
	}
	public int getLimit_person_no() {
		return limit_person_no;
	}
	public void setLimit_person_no(int limit_person_no) {
		this.limit_person_no = limit_person_no;
	}
	public String getPassword() {
		return ( password == null) ? "" : password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public int getLimit_level() {
		return limit_level;
	}
	public void setLimit_level(int limit_level) {
		this.limit_level = limit_level;
	}
	public String getRoomType() {
		return roomType;
	}
	public void setRoomType(String roomType) {
		this.roomType = roomType;
	}

	public char getFinished() {
		return finished;
	}

	public void setFinished(char finished) {
		this.finished = finished;
	}

	public Game getGame() {
		return game;
	}

	public void setGame(Game game) {
		this.game = game;
	}

	public Square getSquare() {
		return square;
	}

	public void setSquare(Square square) {
		this.square = square;
	}

	
	public static class Game{
		public static String GAMETYPE_SCRATCH = "스크라치";
		public static String GAMETYPE_STROKE = "스트로크";
		public static String GAMETYPE_MATCH = "매치";
		public static String GAMETYPE_SKINS = "스킨스";
		
		char playYN;
		int hole_cnt;
		int enzi;
		int course_no;
		int now_hole_no;
		String game_type;
		Course course;
		
		public Game(){}
		public Game(ResultSet rs){
			try {
				setPlayYN(rs.getString("GAMEPLAYYN").charAt(0));
				setHole_cnt(rs.getInt("GAMEHOLENO"));
				setEnzi(rs.getInt("GAMEENZI"));
				setCourse_no(rs.getInt("GAMECRSNO"));
				setGame_type(rs.getString("GAMETYPENAME"));
				setNow_hole_no(rs.getInt("NOWHOLENO"));
				setCourse(DAO.getInstance().getCourse(getCource_no()));
				
				System.out.println("Game()완료");
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		public char getPlayYN() {
			return playYN;
		}
		public void setPlayYN(char playYN) {
			this.playYN = playYN;
		}
		public int getHole_cnt() {
			return hole_cnt;
		}
		public void setHole_cnt(int holeNo) {
			this.hole_cnt = holeNo;
		}
		public int getEnzi() {
			return enzi;
		}
		public void setEnzi(int enzi) {
			this.enzi = enzi;
		}
		public int getCource_no() {
			return course_no;
		}
		public void setCourse_no(int course_cnt) {
			this.course_no = course_cnt;
		}
		public String getGame_type() {
			return game_type;
		}
		public void setGame_type(String game_type) {
			this.game_type = game_type;
		}
		public int getNow_hole_no() {
			return now_hole_no;
		}
		public void setNow_hole_no(int now_hole_no) {
			this.now_hole_no = now_hole_no;
		}
		public Course getCourse() {
			return course;
		}
		public void setCourse(Course course) {
			this.course = course;
		}
		
	}
	
	public static class Square{
		int stamina_charge_speed;
		int stamina_charge_qty;
		
		public Square(){}
		/*
		 * ROOMNO	NUMBER(38,0)
			STAMINACHARGESPD	NUMBER(38,0)
			STAMINACHARGEQTY	NUMBER(38,0)
		 */
		public Square(ResultSet rs){
			try {
				setStamina_charge_speed(rs.getInt("STAMINACHARGESPD"));
				setStamina_charge_qty(rs.getInt("STAMINACHARGEQTY"));
				
				System.out.println("Square()완료");
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		public int getStamina_charge_speed() {
			return stamina_charge_speed;
		}
		public void setStamina_charge_speed(int stamina_charge_speed) {
			this.stamina_charge_speed = stamina_charge_speed;
		}
		public int getStamina_charge_qty() {
			return stamina_charge_qty;
		}
		public void setStamina_charge_qty(int stamina_charge_qty) {
			this.stamina_charge_qty = stamina_charge_qty;
		}

	}
}